import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/net/response/service_order_list_data.dart';
import 'package:ls_work/ui/service_order/service_order_detail_page.dart';
import 'package:ls_work/ui/service_order/service_order_list_page.dart';
import 'package:ls_work/ui/service_order/service_order_rating_page.dart';
import 'package:ls_work/viewmodel/service_order/my_service_order_list_view_model.dart';

class MyServiceOrderListFragment extends BaseStatefulMvvmWidget{
  final String typeId;

  MyServiceOrderListFragment(this.typeId);

  @override
  State<StatefulWidget> createState() =>_MyServiceOrderListState();

}

class _MyServiceOrderListState extends BaseMvvmListState<MyServiceOrderListViewModel,MyServiceOrderListFragment>{
  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return loadingContentWidget;
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Stack(
      children: [
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                CommonText('工单编号：${item.orderServeCode}',
                    textSize: 14, textColor: Color(0xff848689))
                    .setWeight(1),
                CommonText('${!item.rationStatusName.isNullOrEmpty()?item.rationStatusName:item.statusName}',
                    textSize: 15, textColor: statusColor(item.statusId!))
              ],
            ),
            Container(
              height: 5,
            ),
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Icon(
                  Icons.house_rounded,
                  color: Colors.white,
                )
                    .addToContainer(
                    decoration: BoxDecoration(
                        color: Color(0xff3EB9AC),
                        borderRadius: 8.borderRadius),
                    width: 40,
                    height: 40)
                    .addToContainer(margin: EdgeInsets.only(top: 4, right: 12)),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      height: 8,
                    ),
                    CommonText('${item.orderServeItemName}',
                        textSize: 18, fontWeight: FontWeight.w600),
                    Container(
                      height: 8,
                    ),
                    CommonText('预约时间：${item.markDuration ?? ""}',
                        textSize: 14, textColor: Color(0xff848689)),
                    Container(
                      height: 5,
                    ),
                    CommonText('服务对象：${item.orderServeHuman ?? ""}',
                        textSize: 14, textColor: Color(0xff848689)),
                    Container(
                      height: 5,
                    ),
                    CommonText('服务地址：${item.orderServeAddress ?? ""}',
                        textSize: 14, textColor: Color(0xff848689)),
                    Container(
                      height: 5,
                    ),
                    CommonText('联系电话：${item.humanMobile ?? ""}',
                        textSize: 14, textColor: Color(0xff848689)),

                    Container(
                      height: 5,
                    ),
                    CommonText('楼栋楼层：${item.buildingName ?? ""}-${item.floorName??""}',
                        textSize: 14, textColor: Color(0xff848689)),

                    if(item.payStatus!=null)
                      ...[
                        Container(
                          height: 5,
                        ),
                        CommonText('收款状态：${item.payStatus.toString()=='1'?'已收款':'待收款'}',
                            textSize: 14, textColor: item.payStatus==1?Colors.blue:Colors.red),
                      ]
                  ],
                ).setWeight(1)
              ],
            )
          ],
        ),
        rateHandle(item.rationStatus??"").isNotEmpty? ElevatedButton(
            onPressed: () {
              Go().push(ServiceOrderRatingPage(item.id!,));
            },
            style: ButtonStyle(
                shape: WidgetStateProperty.all(StadiumBorder()),
                elevation: WidgetStateProperty.all(0),
                padding: WidgetStateProperty.all(EdgeInsets.symmetric(horizontal: 8)),
                maximumSize:
                WidgetStateProperty.all(Size.fromHeight(36))),
            child: CommonText(rateHandle(item.rationStatus!), textColor: Colors.white, textSize: 14))
            .addToContainer(height: 30, alignment: Alignment.center)
            .setLocation(right: 0, bottom: 0):Container()
      ],
    ).onTap(() {
      Go().push(ServiceOrderDetailPage(
        showDetail: true,
        orderId: item.id!,
      ));
    }).addToContainer(
        decoration:
        BoxDecoration(color: Colors.white, borderRadius: 8.borderRadius),
        margin: EdgeInsets.symmetric(
          horizontal: 16,
        ),
        padding: EdgeInsets.all(10));
  }

  @override
  EdgeInsets get listPadding => EdgeInsets.symmetric(vertical: 10);

  @override
  Widget get separatorDivider => Container(height: 10,);

  @override
  MyServiceOrderListViewModel createViewModel() {
    return MyServiceOrderListViewModel(context,widget.typeId);
  }

  String rateHandle(String statusId){
    switch (statusId) {
      case '10237':
        return '评价';
      default:
        return '';
    }
  }

}
